package com.example.exchangeapp.yy.fragment;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.exchangeapp.R;
import com.example.exchangeapp.yy.entity.GoodVo2;
import com.example.exchangeapp.yy.request.HttpRequestUtils;

import java.util.ArrayList;
import java.util.List;

public class HasSendGoods extends AppCompatActivity{
    //需要适配的数据
    private String[] titles={"桌子","苹果","蛋糕","线衣","猕猴桃","围巾"};
    private String[] prices={"1800元","10元/kg","300元","350元","10元/kg","280元"};
    public static List<GoodVo2> data =new ArrayList<>();
    public static int num =22;
    public static String []imageList ={};
    public static Integer imageNum=0;
    public static Dialog mDialog;
    public static int deletePosition = -1;
    public static  MyBaseAdapter mAdapter;
    public volatile static int code =0;
    public volatile static String msg ="失败";
    public static int index=0;
    Bitmap bmImg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_has_send_goods);

        //初始化ListView控件
        ListView listView=findViewById(R.id.lv);
        //创建一个Adapter的实例
         mAdapter=new MyBaseAdapter();
        //设置Adapter
        listView.setAdapter(mAdapter);
        //重新刷新数据源
        mAdapter.notifyDataSetChanged();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              showDialog(data.get(position),position);
              dialog_goods_details.goodVo2 = data.get(position);
              deletePosition = position;
            }
        });
    }


    private void showDialog(GoodVo2 goods,int position){
      mDialog =   new dialog_goods_details(this,goods,position);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        mDialog.show();


    }



    class MyBaseAdapter extends BaseAdapter {

        @Override
        public int getCount(){       //得到item的总数
            return data.size();
        }

        @Override
        public GoodVo2 getItem(int position){
            return data.get(position); //返回item的数据对象
        }
        @Override
        public long getItemId(int position){
            return position;         //返回item的id
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent){//获取item中的View视图
            ViewHolder holder;
            if(convertView==null){
                convertView=View.inflate(HasSendGoods.this,R.layout.activity_list_item_has_send, null);
                holder=new ViewHolder();
                holder.typeName=convertView.findViewById(R.id.type_name);
                holder.price=convertView.findViewById(R.id.price);
                holder.content=convertView.findViewById(R.id.good_content);
                holder.addr=convertView.findViewById(R.id.addr);
                holder.iv=convertView.findViewById(R.id.iv);
                convertView.setTag(holder);
            }else{
                holder=(ViewHolder)convertView.getTag();
            }
            holder.typeName.setText(data.get(position).typeName);

            holder.price.setText(data.get(position).price.toString());
            holder.content.setText(data.get(position).content.toString());
           holder.addr.setText(data.get(position).addr.toString());
           holder.iv.setImageURL(data.get(position).imageUrlList[0]);
//
            return convertView;
        }
    }
    class ViewHolder{
        TextView typeName;
        TextView price;
        TextView content;
        TextView addr;
        MyImageView iv;
    }





}